/**
 * 
 */
package com.contact.action;

import java.util.List;

import com.contact.model.Contact;
import com.contact.service.ContactService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author David Zheng
 *
 */
public class ContactAction extends ActionSupport {
	
	private ContactService contactService;
	
	private Contact contact;
	
	private List<String> nameList;
	
	private List<Contact> contactList;
	
	private String name;
	
	private int id;
	
	private int limit = 10;
	
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {		
		contactList = contactService.loadAll();
		
		return Action.SUCCESS;
	}
	
	
	
//	public String initContactList() throws Exception{
//		
//		contactList = contactService.load(name);
//		
//		return Action.SUCCESS;
//	}
	
	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String loadContact() throws Exception{
		contact = contactService.loadById(id);
		
		return Action.SUCCESS;
	}
	
	public String verifyAccount() throws Exception{
		//contactService.loadByEmail(name);
		//return Action.INPUT;
		return Action.SUCCESS;
	}
	
	/**
	 * Gets the auto-complete suggestion name list;
	 * @return
	 * @throws Exception
	 */
	public String getAutoCompleteList() throws Exception{
		if (name!= null && name.length()>2) {
			List<String> list = contactService.getAliasListCache();
			nameList = contactService.search(name, list, limit);
		}
				
		return Action.SUCCESS;
	}



	/**
	 * @param contactService the contactService to set
	 */
	public void setContactService(ContactService contactService) {
		this.contactService = contactService;
	}



	/**
	 * @return the contact
	 */
	public Contact getContact() {
		return contact;
	}



	/**
	 * @return the contactList
	 */
	public List<Contact> getContactList() {
		return contactList;
	}



	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	
	
	
	
	

}
